var base = getApp();
Page({
    data: {
        userInfo: {},
        jzb: "0.00",
        loaded: true,
        exp: 0,
        phone: "",
        levels: 0,
        headimg: "https://wxapp.youmeng.com/static/images/icon_user.jpg",
        orderNum:{
          wait_payment: 0,
          wait_deliver: 0,
          wait_receipt: 0,
          wait_comment: 0,
        }
    },
    exist: function () {
        base.user.userid = 0;
        base.user.sessionid = "";
        base.user.clear();     
        wx.redirectTo({
            //url: '../phone/phone'
        });
    },
    onReady: function () {
        // 页面渲染完成

    },
    onShareAppMessage: function () {
      return {
        title: base.user.shareTitle,
        desc: base.user.shareDesc,
        path: '/pages/index/index',
        success: function (res) {
          // 转发成功
        },
        fail: function (res) {
          // 转发失败
        }
      }
    },
    tomyorder: function () {
        wx.navigateTo({
            url: '../user/myorder/myorder'
        })
    },
    bindAddress:function(){
      wx.chooseAddress({
        success: function (res) {
          var content = res.userName + "," + res.postalCode + "," + res.provinceName + "," + res.cityName + "," + res.countyName + "," + res.detailInfo + "," + res.nationalCode + "," + res.telNumber
          wx.showModal({
            title: '提示',
            content: content
          })
        }
      })
    },
    onShow: function () {
        var that = this;
        var orderNum={};
        wx.request({
          url: base.path.api + 'Member.UserCenter',
          data: {
            md5key: base.user.session_key,
            aid: base.user.aid
          },
          async: false,
          method: "POST",
          header: base.user.header,
          success: function (response) {
            var result = response.data;
            if (result.ret == 200) {
              orderNum.wait_payment = parseInt(result.data.wait_payment);
              orderNum.wait_deliver = parseInt(result.data.wait_deliver);
              orderNum.wait_receipt = parseInt(result.data.wait_receipt);
              orderNum.wait_comment = parseInt(result.data.wait_comment);
              that.setData({
                orderNum:orderNum
              })
            } else {
              wx.showModal({
                showCancel: false,
                title: '',
                content: result.msg
              });
            }
          }
        });

        base.getUserInfo(function (userInfo) {
          that.setData({
            userInfo: userInfo,
            orderNum: orderNum
          })
        });

    },

    // 拨打电话
    bindTel:function(){
      wx.makePhoneCall({
        phoneNumber: '021-52682991' //仅为示例，并非真实的电话号码
      })
    }
});